package com.niiwoo.civet.trade.configuration;

import com.niiwoo.civet.trade.constant.RabbitConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 资金端 mq 配置.
 *
 * @author lichuanzhi
 * @date 2018/01/26
 */

@Configuration
public class FundMqConfiguration {

    /**
     * 定时更新资金端，罚息和标的逾期状态
     */
    @Bean
    public Exchange fundRepay(RabbitAdmin admin) {
        Exchange exchange = new DirectExchange(RabbitConstant.Exchange.FUND_REPAY, true, true);
        admin.declareExchange(exchange);
        return exchange;
    }
    @Bean
    public Queue fundRepayUpdatePenalty(RabbitAdmin admin) {
        Queue queue = new Queue(RabbitConstant.Queue.FUND_REPAY_UPDATE_PENALTY, true);
        admin.declareQueue(queue);
        return queue;
    }
    @Bean
    public Binding fundRepayUpdatePenaltyBinding(RabbitAdmin admin) {
        Binding binding = BindingBuilder.bind(fundRepayUpdatePenalty(admin)).to(fundRepay(admin)).with(RabbitConstant.RoutingKey.FUND_REPAY_UPDATE_PENALTY).noargs();
        admin.declareBinding(binding);
        return binding;
    }
}
